﻿@using Abp.Authorization;
@using FwProject.Web.Models;
@model RoleGrantViewModel
@{
    ViewBag.Title = "角色权限设置";
    Permission rootPermission = Model.SystemPermissions.FirstOrDefault(o => o.Name == "ShopApp");//获取饭碗易购根权限，其他所有权限分类都在其下面，具体配置在 Core领域层/Authorization/OAAuthorizationProvider.cs中
}
@section styles{
    <link href="~/Theme/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link rel="icon" href="/fwyg_favicon.ico" type="image/x-icon" />
    <link href="/Content/bootstrap.css" rel="stylesheet" />
    <link href="/Theme/css/font-awesome.min93e3.css?" rel="stylesheet" />
    <link href="/Theme/css/animate.min.css" rel="stylesheet" />
    <link href="/Theme/css/style.min862f.css?" rel="stylesheet" />
    <link href="/Theme/js/plugins/layer/skin/layer.css" rel="stylesheet" />
    <link href="/css/main.css" rel="stylesheet" />

    <style type="text/css">
        .table > tbody > tr > td, .table > tbody > tr > th, .table > tfoot > tr > td, .table > tfoot > tr > th, .table > thead > tr > td, .table > thead > tr > th {
            border-top: none;
            padding: 2px;
        }
    </style>
}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-md-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>角色权限分配 <small>请谨慎设置</small></h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <p class="text-muted">分配权限的时候不要把自己的分配权限的权限给取消了。</p>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <form id="form0" class="form-horizontal" action="/Roles/UpdatePermissions?id=@ViewBag.Id" method="post" data-ajax="true" novalidate="novalidate" data-ajax-success="ReloadAjaxCallback" data-ajax-failure="FailureAjaxCallback" data-ajax-method="Post" role="form">
            @Html.AntiForgeryToken()
            @foreach (var p in rootPermission.Children)
            {
                //if (p.Name == PermissionNames.Pages_Tenants) { continue; }
                //if (p.Name == PermissionNames.Admin) { continue; }
                <div class="col-sm-12 col-xs-12 fuck">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5 name="chkH5" class="checkbox i-checks che">
                                <label>
                                    <input type="checkbox" name="GrantedPermissionNames[]" value="@p.Name" @(Model.RolePermissions.Contains(p) ? "checked" : "")> <i></i>
                                    @(((Abp.Localization.LocalizableString)p.DisplayName).Name)

                                </label>
                            </h5>
                            <div class="ibox-tools">
                                <a class="collapse-link">
                                    <i class="fa fa-chevron-up"></i>
                                </a>
                            </div>
                        </div>
                        <div class="ibox-content">
                            <div class="form-group">
                                @if (p.Children != null && p.Children.Count > 0)
                                {
                                    foreach (var c in p.Children)
                                    {

                                        <div class="panel panel-default">
                                            <div class="panel-heading">
                                                <h5 class="panel-title">
                                                    <a data-toggle="collapse" data-parent="#accordion" href="tabs_panels.html#collapseOne">@(((Abp.Localization.LocalizableString)c.DisplayName).Name)</a>
                                                </h5>
                                            </div>
                                            <div id="collapseOne" class="panel-collapse collapse in">
                                                <div class="panel-body">
                                                    @if (c.Children != null && c.Children.Count > 0)
                                                    {
                                                        foreach (var d in c.Children)
                                                        {
                                                            <div class="checkbox i-checks">
                                                                <label>
                                                                    <input type="checkbox" name="GrantedPermissionNames[]" value="@d.Name" @(Model.RolePermissions.Contains(d) ? "checked" : "")> <i></i> @(((Abp.Localization.LocalizableString)d.DisplayName).Name)
                                                                </label>
                                                            </div>
                                                            if (d.Children != null && d.Children.Count > 0)
                                                            {
                                                                foreach (var i in d.Children)
                                                                {
                                                                    <div class="checkbox i-checks">
                                                                        <label>
                                                                            <input type="checkbox" name="GrantedPermissionNames[]" value="@i.Name" @(Model.RolePermissions.Contains(i) ? "checked" : "")> <i></i> @(((Abp.Localization.LocalizableString)i.DisplayName).Name)
                                                                        </label>
                                                                    </div>
                                                                }

                                                            }
                                                        }
                                                    }
                                                </div>
                                            </div>
                                        </div>


                                    }
                                }
                            </div>
                        </div>
                    </div>
                </div>
            }
            <div class="col-md-12 fuck">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <button type="submit" class="btn btn-primary" data-loading-text="执行中...">保存</button> &nbsp;&nbsp;
                        <button type="reset" class="btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="modal_ajax" class="modal inmodal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
</div>
@section scripts{
    <script src="/Scripts/jquery-3.1.1.min.js"></script>
    <script src="/Scripts/json2.js"></script>
    <script src="/Scripts/jquery.serialize-object.min.js"></script>
    <script src="/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script src="/Scripts/bootstrap.min.js?v=NkYOSU5MYoRDr97UCydDte3ppKdvtPe57yNFzH5Z_WQ"></script>
    <script src="/Scripts/jquery.validate.min.js"></script>
    <script src="/Scripts/jquery.validate.unobtrusive.min.js"></script>
    <script src="/Theme/js/plugins/layer/layer.min.js"></script>
    <script src="/lib/abp-web-resources/Abp/Framework/scripts/abp.js"></script>
    <script src="/lib/abp-web-resources/Abp/Framework/scripts/libs/abp.jquery.js"></script>
    <script src="/js/main.js"></script>

    <script src="~/Theme/js/content.min.js?v=1.0.0"></script>
    <script src="~/Scripts/masonry.pkgd.min.js"></script>
    <script src="~/Theme/js/plugins/iCheck/icheck.min.js"></script>
    <script type="text/javascript">
        //layer.msg("test",{time:2000});
        $(document).ready(function () {
            $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", });
            $("#form0").masonry({ itemSelector: ".fuck" });


            $('.che').on('ifChecked', function (event) { //ifCreated 事件应该在插件初始化之前绑定

                //$($(this).parent().nextSibling).find('.i-checks').iCheck('check');
                $(this).parent().siblings(".ibox-content").find('.i-checks').iCheck('check');
            });
            $('.che').on('ifUnchecked', function (event) { //ifCreated 事件应该在插件初始化之前绑定

                $(this).parent().siblings(".ibox-content").find('.i-checks').iCheck('uncheck');
            });
        });

        function ReloadAjaxCallback(data) {
            if (data.success) {
                layer.msg("操作成功！", {
                    icon: 1,
                    time: 2000
                }, function () {
                    window.location.reload();
                });
            }
            else if (data.unAuthorizedRequest) {
                layer.msg('登录信息丢失或你没有权限进行此操作，重新登录或切换登录帐号重试！', {
                    icon: data.error.code,
                    time: 2000
                });
            }
            else {
                layer.msg('操作失败：' + data.error.message, {
                    icon: data.error.code,
                });
            }
        }
    </script>
}